#!/usr/bin/perl -w 

use strict;
use XML::LibXML;

my $source_file = shift;

my $parser = XML::LibXML->new();
my $tree = $parser->parse_file($source_file);
my $xpc = XML::LibXML::XPathContext->new($tree);
my @n = $xpc->findnodes('//sourcecode'); 

my @tanglefile;

foreach my $nod (@n) {
    $tanglefile[$nod->getAttribute('position')] =  $nod->getFirstChild()->getData;
}

foreach my $fragment (@tanglefile) {
    unless ($fragment =~ /^$/) {
        print $fragment;
    }
}
